/*
 * @Author: taosong 2289713738@qq.com
 * @Date: 2023-12-27 16:20:06
 * @LastEditors: taosong 2289713738@qq.com
 * @LastEditTime: 2023-12-27 16:21:56
 * @FilePath: \ele-h5\src\use\useTimeout.ts
 * @Description: 
 * 
 * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved. 
 */
import { onUnmounted } from "vue"
export const useTimeout = (fn: () => void, delay: number) => {
  const timer = setTimeout(() => {
    fn()
  }, delay)
  
  const clear = () => {
    clearTimeout(timer)
  }

  onUnmounted(clear)

  return clear
}